package cp3120.ucm.client;

import cp3120.ucm.*;
import cp3120.dao.DAOFactory;
import cp3120.view.MainUI;
import cp3120.model.User;

/**
 * @author Adam Scarr
 * @author Rowan Spence
 * UC CREATING AN ACCOUNT
 *
 * PRECONDITION: The system has displayed the register user interface<br>
 * POST-CONDITION: The User is returned to the previous user interface <br>
 * USER: A customer wishing to create an account<br>
 * 1. System creates a new user and populate it with data from the form<br>
 * 2. System commits the user to the database<br>
 * 3. System closes the registration interface<br>
 * 2a. System could not commit and displays an error<br>
 */
public class UCRegisterUser implements UCController {
    /**
     * runs this UC
     */
    public void run() {
        User user = new User();
        MainUI.getInstance().getRegistrationUI().insertInto(user);

        DAOFactory.getUserDAO().addUser(user);
        MainUI.getInstance().getRegistrationUI().setVisible(false);
        MainUI.getInstance().getRegistrationUI().setError(null);
    }
}
